package com.bom.core.util.jwt;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTHeader;
import cn.hutool.jwt.signers.JWTSignerUtil;
import lombok.experimental.UtilityClass;

import java.util.Date;

@UtilityClass
public class Jwts {

    public void ass() {
      byte[] key = "123".getBytes();
  /*        String rightToken = JWT.create()
                .setHeader("bibibi", "bibi")
                .setPayload("phone1", "13657244791")
                .setPayload("phone2", "13657244792")
                .setPayload("phone3", "13657244793")
                .setExpiresAt(DateUtil.offset(new Date(), DateField.SECOND, 30))
                .setSigner(JWTSignerUtil.hs256(key))
                .sign();
        System.out.println(rightToken);
        JWT jwt = JWT.of(rightToken);
// JWT
        Object header1 = jwt.getHeader(JWTHeader.TYPE);
// HS256
        Object header = jwt.getHeader(JWTHeader.ALGORITHM);

// 1234567890
        Object sub = jwt.getPayload("phone1");
// looly
        Object name = jwt.getPayload("phone2");
// true
        Object admin = jwt.getPayload("phone3");
// 默认验证HS265的算法
        // 密钥
        boolean verify = JWT.of(rightToken).setKey(key).verify();

        System.out.println(verify);
        ThreadUtil.safeSleep(40000);*/
        boolean verify = JWT.of("eyJ0eXAiOiJKV1QiLCJiaWJpYmkiOiJiaWJpIiwiYWxnIjoiSFMyNTYifQ.eyJwaG9uZTEiOiIxMzY1NzI0NDc5MSIsInBob25lMiI6IjEzNjU3MjQ0NzkyIiwicGhvbmUzIjoiMTM2NTcyNDQ3OTMiLCJleHAiOjE2NDAwNzM2MTl9.V6YL-RBIifaCW53O2").setKey(key).validate(10000);
        System.out.println(verify);
    }

    public static void main(String[] args) {
        ass();
    }
}
